﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using FileDFS.Model;
using FileDFS.Bll;
using System.IO;
/*
 * Coder:Tieria
 * WriteTime:2015.5.13
 * FileName:FileService.cs
 * ReMark:分布式文件系统具体操作
 */
namespace FileDFS.WcfHost
{
     [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,IncludeExceptionDetailInFaults = true)]
    public class FileService : IFileService
    {

        #region 检测当前服务是否可用
        /// <summary>
        /// 检测当前服务是否可用
        /// </summary>
        /// <returns></returns>
        public string ServerCheck()
        {
            return "ok";
        } 
        #endregion

        #region 上传图片
        public ImageUploadResult Upload_Image(ImageUploadModel imageUploadModel)
        {
            ImageResultBody resultBody = ImageHandler.GetInstance().SaveImage(imageUploadModel);
            ImageUploadResult result = new ImageUploadResult()
            {
                ResultBody = resultBody
            };
            return result;
        } 
        #endregion

        #region 上传文件
        public FileUploadResult Upload_File(FileUploadModel fileUploadModel)
        {
            FileResultBody resultBody = FileHandler.GetInstance().SaveFile(fileUploadModel);
            FileUploadResult result = new FileUploadResult()
            {
                ResultBody=resultBody
            };
            return result;
        } 
        #endregion

        #region 下载某张图片的缩略图
        public ThumbnailDownloadResult Download_ImageThumbnail(ThumbnailDownloadModel downloadModel)
        {
            ThumbnailDownloadResult result = DownloadHandler.GetInstance().DownloadThumbnail(downloadModel);
            return result;
        } 
        #endregion

        #region 下载小文件或者图片
        public DownloadResult Download_SingleFile(DownloadModel downloadModel)
        {
            DownloadResult result = DownloadHandler.GetInstance().DownloadSingle(downloadModel);
            return result;
        } 
        #endregion

        #region 批量删除文件或图片
        public bool Bulk_Delete(List<DeleteModel> deleteList)
        {
            return  DeleteHandler.GetInstance().DeleteFiles(deleteList);
        } 
        #endregion

        #region 获取当前节点的全部的根目录信息
        /// <summary>
        /// 返回全部的根目录信息
        /// </summary>
        /// <returns></returns>
        public List<FolderInfoModel> GetAllFloders()
        {
            List<FolderInfoModel> folderList = FolderSizeHandler.GetInstance().GetAllFolders();
            return folderList;
        } 
        #endregion 

        #region 获取某个集合列表中文件的大小
        /// <summary>
        /// 获取某个集合列表中文件的大小
        /// </summary>
        /// <param name="virtualPathList">虚拟路径列表</param>
        /// <returns>全部文件的大小综合,以MB为单位</returns>
        public double GetFilesSize(List<string> virtualPathList)
        {
            double sizeCount = FolderSizeHandler.GetInstance().GetListFilesSize(virtualPathList);
            return sizeCount;
        } 
        #endregion

    }
}
